package com.gujianjian.mybatis;

import com.gujianjian.mybatis.dao.DepartmentDaoImpl;
import com.gujianjian.mybatis.entity.Department;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MyApplication2 {

    public static void main(String[] args) throws IOException {

        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);


        DepartmentDaoImpl departmentDao = new DepartmentDaoImpl(sqlSessionFactory);
        List<Department> list = departmentDao.findAll();
        Department department = departmentDao.findById("18ec781fbefd727923b0d35740b177ab");
//        list.forEach(System.out::println);

        System.out.println(department);
    }
}
